package main.java.view;


import main.java.controller.AppointmentController;
import main.java.controller.DoctorController;
import main.java.controller.PatientController;
import main.java.dao.UserDao;
import main.java.dao.impl.UserDaoImpl;
import main.java.polo.User;

import java.util.Scanner;

import static main.java.constant.ColumnConstant.control;

public class UserView {
    /**
     * 登录界面
     * @return true表示登录成功，false表示登录失败
     */
    public static String loginView() {
        System.out.println("欢迎来到登录界面");
        System.out.println("用户注册请按1，登录请按2");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        System.out.println("请输入用户名");
        String userName = scanner.next();
        System.out.println("请输入密码");
        String userPassword = scanner.next();
        UserDao userDao = new UserDaoImpl();
        User user;
        if (i == 1) {
            user = new User(null, userName, userPassword, null, null, null);
            if (userDao.insertBasic(user) == 1) {
                System.out.println("注册成功");
                return userName;
            } else {
                System.out.println("注册失败");
            }
        } else if (i == 2) {
            user = userDao.selectByNameAndPassword(userName, userPassword);
            if (user != null) {
                System.out.println("登录成功");
                return userName;
            } else {
                System.out.println("登录失败");
            }
        }
        return null;
    }

    public void mainView() {
        System.out.println("欢迎来到主界面");
        System.out.println("===========================");
        System.out.println("1.完善个人信息");
        System.out.println("2.预约挂号信息管理");
        System.out.println("3.患者信息管理");
        System.out.println("4.医生信息管理");
        System.out.println("5.退出登录");
        System.out.println("===========================");
    }

    public void doctorView() {
        while (control){
            System.out.println("===========================");
            System.out.println("1.添加新医生");
            System.out.println("2.更改医生信息");
            System.out.println("3.删除医生");
            System.out.println("4.查询医生信息");
            System.out.println("5.返回主界面");
            System.out.println("===========================");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    if (DoctorController.insert() == 1) {
                        System.out.println("添加成功");
                    } else {
                        System.out.println("添加失败");
                    }
                    break;
                case 2:
                    if (DoctorController.update()== 1) {
                        System.out.println("更改成功");
                    } else {
                        System.out.println("更改失败");
                    }
                    break;
                case 3:
                    if (DoctorController.delete()== 1) {
                        System.out.println("删除成功");
                    } else {
                        System.out.println("删除失败");
                    }
                    break;
                case 4:
                    DoctorController.selectAll();
                    break;
                case 5:
                    control = false;
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
            }
        }
    }

    public void appointmentView() {
        while (control){
            System.out.println("===========================");
            System.out.println("1.预约挂号");
            System.out.println("2.预约记录");
            System.out.println("3.返回主界面");
            System.out.println("===========================");
            Scanner scanner = new Scanner(System.in);
                int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    AppointmentController.selectDoctor();
                    if (AppointmentController.insert() == 1) {
                        System.out.println("预约成功");
                    } else {
                        System.out.println("预约失败");
                    }
                    break;
                case 2:
                    AppointmentController.selectRecord();
                    System.out.println("取消预约请按1");
                    int result = scanner.nextInt();
                    if (result == 1) {
                        if (AppointmentController.delete() == 1) {
                            System.out.println("取消预约成功");
                        } else {
                            System.out.println("取消预约失败");
                        }
                    }
                    break;
                case 3:
                    control=false;
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
            }
        }
    }

    public void patientView() {
        while (control){
            System.out.println("===========================");
            System.out.println("1.查看患者信息");
            System.out.println("2.添加患者信息");
            System.out.println("3.删除患者信息");
            System.out.println("4.返回主界面");
            System.out.println("===========================");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    PatientController.selectAll();
                    break;
                case 2:
                    if (PatientController.insert() == 1) {
                        System.out.println("添加成功");
                    } else {
                        System.out.println("添加失败");
                    }
                    break;
                case 3:
                    if (PatientController.delete() == 1) {
                        System.out.println("删除成功");
                    } else {
                       System.out.println("删除失败");
                    }
                    break;
                case 4:
                    control=false;
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
            }
        }
    }
}
